/*
 * Copyright 2016 drakeet. https://github.com/drakeet
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.epfresh.adapter;

import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.epfresh.R;
import com.epfresh.activity.CommonStoreActivity;
import com.epfresh.api.widget.tablayout.SlidingTabLayout;
import com.epfresh.bean.HomeGoodsOften;
import com.umeng.analytics.MobclickAgent;

import multitype.ItemViewBinder;

import  com.epfresh.api.widget.tablayout.listener.*;

public class ViewBinderHomeOftenCategory
        extends ItemViewBinder<HomeGoodsOften, ViewBinderHomeOftenCategory.ViewHolder>{//} implements View.OnClickListener {
    OnTabSelectListener onRecyclerViewItemClickListener;

    public OnTabSelectListener getOnRecyclerViewItemClickListener() {
        return onRecyclerViewItemClickListener;
    }

    public void setOnRecyclerViewItemClickListener(OnTabSelectListener onRecyclerViewItemClickListener) {
        this.onRecyclerViewItemClickListener = onRecyclerViewItemClickListener;
    }
/*
    @Override
    public void onClick(View v) {
        Object o = v.getTag(R.id.item_key_status);
        if (o instanceof HomeGoodsOften) {
            HomeGoodsOften bean = ((HomeGoodsOften) o);
            MobclickAgent.onEvent(v.getContext(), "Click_Click_HomeRecommend");*//*统计广告点击*//*
            Intent storeIntent = new Intent(v.getContext(),
                    CommonStoreActivity.class);
            v.getContext().startActivity(storeIntent);
        }
    }*/

    @NonNull
    @Override
    protected ViewHolder onCreateViewHolder(
            @NonNull LayoutInflater inflater, @NonNull ViewGroup parent) {
        View view = inflater.inflate(R.layout.include_home_often_category, parent, false);
        return new ViewHolder(view);
    }


    @Override
    protected void onBindViewHolder(@NonNull ViewHolder holder, @NonNull HomeGoodsOften bean) {
        holder.lyTab.setOnTabSelectListener(onRecyclerViewItemClickListener);
        String[] titles = new String[bean.getTopCategory().size()];
        int position = 0;
        for(int i=0;i<bean.getTopCategory().size();i++){
            titles[i] = bean.getTopCategory().get(i).getName();
            if(bean.getTopCategory().get(i).isSelect())
                position = i;
        }
        holder.lyTab.setTitles(titles);
        holder.lyTab.setCurrentTab(position);

    }


    static class ViewHolder extends RecyclerView.ViewHolder {
        private SlidingTabLayout lyTab;

        ViewHolder(@NonNull View itemView) {
            super(itemView);
            lyTab = (SlidingTabLayout) itemView.findViewById(R.id.ly_often_category);
        }
    }
}
